package com.hspedu.reflection.question;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/3/21
 * @time 17:10
 */
public class ReflectionQuestion {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        Properties properties = new Properties();
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream("D:\\workspace_idea\\java0\\hspedu\\chapter23\\src\\re.properties");
            properties.load(fileInputStream);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String catPath = properties.getProperty("classfullpath");
        String methodName = properties.getProperty("method");

        //1. 先加载类，aClass对象的类型是Class
        Class aClass = Class.forName(catPath);
        //2. 通过这个对象得到需要加载的类的对象实例
        Object o = aClass.newInstance();
        //3. 获取方法对象
        Method method = aClass.getMethod(methodName);
        System.out.println("==================");
        //4. 调用方法，通过对象方法对象来调用
        method.invoke(o);

    }
}
